package org.example.ui;

import org.example.chrome.ChromeUtils;
import org.openqa.selenium.WebDriver;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class WindowNotifier extends WindowAdapter implements WindowListener {
    public WindowNotifier() {
        super();
    }

    @Override
    public void windowClosing(WindowEvent e)
    {
        super.windowClosing(e);
        System.out.println(e.getComponent().getClass().getSimpleName() +".windowClosing fired, 111");
        for (WebDriver driver : ChromeUtils.DRIVERS) {
            driver.quit();
        }
        ChromeUtils.SERVICE.stop();
    }

    @Override
    public void windowClosed(WindowEvent e) {
        super.windowClosed(e); //To change body of generated methods, choose Tools | Templates.
        System.out.println(e.getComponent().getClass().getSimpleName() +".windowClosed fired, 333");
    }

    @Override
    public void windowDeactivated(WindowEvent e) {
        super.windowDeactivated(e);
        System.out.println(e.getComponent().getClass().getSimpleName() +".windowDeactivated fired, 222");
    }
}
